import React, { Component } from 'react'
import ThemeContext from './ThemeContext'

export default class VoteMain extends Component {
    // 如果不写下行代码，this.context={}
    static contextType = ThemeContext
    render() {
        let { supNum, oppNum } = this.context // {supNum: 10, oppNum: 5, change: ƒ}
        console.log('context',this.context);
        let total = supNum + oppNum,
            ratio = '--';
        if (total > 0) ratio = (supNum / total * 100).toFixed(2) + '%';
        return (
            <div className="main">
                <p>支持人数：{supNum}人</p>
                <p>反对人数：{oppNum}人</p>
                <p>支持比率：{ratio}</p>
            </div>
        )
    }
}
